<?php
define( '_VALID_MOS', 1 );
require( '../globals.php' );
require( '../configuration.php' );
require_once( '../includes/joomla.php' );
require_once( '../language/english.php' );

$nameID			= intval(mosGetParam($_REQUEST, 'nameID', 0));
$hangID			= intval(mosGetParam($_REQUEST, 'hangID', 0));
$frame			= mosGetParam($_REQUEST, 'frame', '');

if ($nameID==0){
	$whereID = "";	
}else{
	$whereID = " AND catid=".$nameID;
}
if ($hangID==0){
	$whereHangID = "";	
}else{
	$whereHangID = " AND catphone_id=".$hangID;
}
if ($frame=='D300k'){
	$whereFrame = " AND ((price<300000 AND price>0) OR (price_giam<300000 AND price_giam>0))";
}else if($frame=='300k_500k'){
	$whereFrame = " AND ((price<500000 AND price>=300000) OR (price_giam<500000 AND price_giam>=300000))";
}else if($frame=='500k_1MB'){
	$whereFrame = " AND ((price<1000000 AND price>=500000) OR (price_giam<1000000 AND price_giam>=500000))";
}else if($frame=='1MB_3MB'){
	$whereFrame = " AND ((price<3000000 AND price>=1000000) OR (price_giam<3000000 AND price_giam>=1000000))";
}else if($frame=='3MB_5MB'){
	$whereFrame = " AND ((price<5000000 AND price>=3000000) OR (price_giam<5000000 AND price_giam>=3000000))";
}else if($frame=='5MB_10MB'){
	$whereFrame = " AND ((price<10000000 AND price>=5000000) OR (price_giam<10000000 AND price_giam>=5000000))";
}else if($frame=='H10MB'){
	$whereFrame = " AND (price>10000000 OR price_giam>10000000)";
}else{
	$whereFrame = "";
}

$sql = "SELECT COUNT(*) FROM #__content WHERE state=1 AND sectionid=1".$whereID.$whereHangID.$whereFrame;
$database->setQuery($sql);
$total = $database->loadResult();
$sql = "SELECT * FROM #__content WHERE state=1 AND sectionid=1".$whereID.$whereHangID.$whereFrame." ORDER BY ordering ASC, id DESC";
$database->setQuery( $sql, $limitstart, $numberPage );
$rows = $database->loadObjectlist();
$url = $mosConfig_live_site."/administrator/components/com_content/uploads/";
?>
<div class="content_main">
	<div class="title_main"><span>Tìm thấy (<?php echo $total;?>) sản phẩm</span></div>
	<div class="show_content">
	<?php
	if ($total==0){
	?>
	<p style="text-align:center; color:red; line-height:30px;">
	Không tìm thấy sản phẩm nào trong danh mục này !
	</p>
	<?php
	}
	for ($i=0; $i<count($rows); $i++){
	$link = "index.php?option=com_content&task=view&catid=".$rows[$i]->catid."&id=".$rows[$i]->id;
	?>
	<div class="boxproduct">
		<div class="image" id="productImageWrapID_<?php echo $rows[$i]->id;?>">
			<?php
			if ($rows[$i]->img!=''){
			?>
			<a href="<?php echo $link;?>"><img src="<?php echo $url.$rows[$i]->img;?>" /></a>
			<?php
			}else{
			?>
			<a href="<?php echo $link;?>"><img src="<?php echo $url;?>no_pic.gif" /></a>
			<?php
			}
			?>
		</div>
		<div class="field"><a href="<?php echo $link;?>"><?php echo $rows[$i]->title;?></a></div>
		<div class="price">Giá : <?php echo number_format($rows[$i]->price,0,',','.');?> VNĐ</div>
		<div class="field">
			<?php if ($rows[$i]->status==1){?>
			<div class="cart">
				<a id="ajax<?php echo $rows[$i]->id;?>">
					<img src="<?php echo $mosConfig_live_site;?>/templates/vnig/images/cart.jpg" border="0" id="featuredProduct_<?php echo $rows[$i]->id;?>" />
				</a>
			</div>
			<?php }else if ($rows[$i]->status==2){?>
			<div class="cart" style="color:#ff7700;">Chưa có hàng</div>
			<?php }else{?>
			<div class="cart" style="color:red;">Hết hàng</div>
			<?php }?>
			<div class="detail"><a href="<?php echo $link;?>">Chi tiết</a></div>
		</div>
	</div>
	<?php
	}
	?>
	</div>
	<script type="text/javascript">
	$(function() {
		<?php 
		for ($i=0; $i<count($rows); $i++){
		?>
		$('#ajax<?php echo $rows[$i]->id;?>').click(function() {
			$('#gio_hang').load('<?php echo $mosConfig_live_site;?>/ajax/orderonline.php?id=<?php echo $rows[$i]->id;?>');
		});
		<?php }?>
	});
	</script>
</div>